
program simpson

    implicit none
    real a, b,  fa, fb, x, f2, f4, h, s
    integer n, i
    print *, 'please input a,b (integral from a to b) and n in space'
    read(*, *) a, b, n
    h=(b-a)/2/n
    s=0.0
    fa=sin(a)+cos(a)
    fb=sin(b)+cos(b)
    x=a+h
    f2=0.0
    f4=sin(x)+cos(x)
    do 10, i=1,n-1
        x=x+h
        f2=f2+sin(x)+cos(x)
        x=x+h
        f4=f4+sin(x)+cos(x)
    10 continue
    s=h/3.0*(fa+fb+4.0*f4+2.0*f2)
    print *, 'integral=', s
end program

